package com.mobileares.midp.demo.client.page;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.user.client.ui.Widget;
import com.mobileares.midp.widgets.client.button.ButtonBar;
import com.mobileares.midp.widgets.client.button.CButton;
import com.mobileares.midp.widgets.client.menu.GWTMenu;
import com.mobileares.midp.widgets.client.menu.GWTMenuItem;
import com.mobileares.midp.widgets.client.menu.PopMenu;
import com.nexustar.gwt.widgets.client.ui.toolbar.MyMenuBar;
import com.nexustar.gwt.widgets.client.ui.toolbar.MyMenuItem;

/**
 * Created by IntelliJ IDEA.
 * User: Tom
 * Date: 2011-7-22
 * Time: 17:20:16
 * To change this template use File | Settings | File Templates.
 */
public class Button extends Composite {
    private FlowPanel panel;
    private CButton test;

    public Button() {
        panel = new FlowPanel();
        initWidget(panel);
        t();

    }

    private void t() {
        ButtonBar bar = new ButtonBar();
        bar.addButton(new CButton("添加"));
        bar.addButton(new CButton("删除"));
        bar.addButton(new CButton("修改"));
        bar.addButton(new CButton("修改业务"));
        test = new CButton("测试");
        CButton max = new CButton("变大");

        bar.addButton(test);
        bar.addButton(max);
        panel.add(bar);
        panel.add(getMenuBar());

       final PopMenu pm = new PopMenu(test);
        pm.addMenuItem("AAAA", new Command() {
            public void execute() {
                //To change body of implemented methods use File | Settings | File Templates.
            }
        });
        pm.addMenuItem("BBBB", new Command() {
            public void execute() {
                //To change body of implemented methods use File | Settings | File Templates.
            }
        });
        test.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent clickEvent) {
                pm.show(10,10);
            }
        });

    }

    private Widget getMenuBar() {

        GWTMenu m1 = new GWTMenu();
        GWTMenuItem i2 = new GWTMenuItem("修改", new Command() {
            public void execute() {
                //To change body of implemented methods use File | Settings | File Templates.
            }
        });
        GWTMenuItem i3 = new GWTMenuItem("删除", new Command() {
            public void execute() {
//                this.setEnable(false);
            }
        });
        GWTMenu v2 = new GWTMenu(true);
        v2.setStylePrimaryName("myMenuBar");

        v2.addItem(new GWTMenuItem("发给自己", new Command() {
            public void execute() {
                //To change body of implemented methods use File | Settings | File Templates.
            }
        }));
        v2.addItem(new GWTMenuItem("发给她", new Command() {
            public void execute() {
                //To change body of implemented methods use File | Settings | File Templates.
            }
        }));

        GWTMenu v1 = new GWTMenu(true);
        v1.setStylePrimaryName("myMenuBar");
        v1.addItem(new MenuItem("一条短信", v2));
        v1.addItem(new MenuItem("多条短信", new Command() {
            public void execute() {
                //To change body of implemented methods use File | Settings | File Templates.
            }
        }));

        GWTMenuItem i1 = new GWTMenuItem("添加", v1);

        m1.addItem(i1);
        m1.addItem(i2);
        m1.addItem(i3);
        i2.setEnable(false);
        return m1;
    }
}
